package com.neusoft.NursingHome.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.NursingHome.po.OutRecord;
import com.neusoft.NursingHome.po.ResponseBean;
import com.neusoft.NursingHome.service.OutRecordService;

@RestController
@RequestMapping("/outrecord")
public class OutRecordController {

    @Autowired
    private OutRecordService outRecordService;

    /**
     * 查询所有的外出记录
     * @return 包含所有外出记录列表的 ResponseBean
     */
    @GetMapping("/all")
    public ResponseBean<List<OutRecord>> getAllOutRecords() {
        List<OutRecord> outRecords = outRecordService.getAllOutRecords();
        return new ResponseBean<>(outRecords);
    }

    /**
     * 根据审核状态查询外出记录
     * @param status 审核状态 (0:已提交, 1:审核通过, 2:审核不通过)
     * @return 包含符合条件的外出记录列表的 ResponseBean
     */
    @GetMapping("/status/{status}")
    public ResponseBean<List<OutRecord>> getOutRecordsByStatus(@PathVariable Integer status) {
        List<OutRecord> outRecords = outRecordService.getOutRecordsByStatus(status);
        return new ResponseBean<>(outRecords);
    }

    /**
     * 通过客户姓名模糊查询外出记录
     * @param name 客户姓名
     * @return 包含符合条件的外出记录列表的 ResponseBean
     */
    @GetMapping("/searchByName/{name}")
    public ResponseBean<List<OutRecord>> searchOutRecordsByName(@PathVariable String name) {
        List<OutRecord> outRecords = outRecordService.searchOutRecordsByName(name);
        return new ResponseBean<>(outRecords);
    }

    /**
     * 添加外出记录
     * @param outRecord 外出记录对象
     * @return 添加结果的 ResponseBean
     */
    @PostMapping("/add")
    public ResponseBean<Boolean> addOutRecord(@RequestBody OutRecord outRecord) {
        boolean result = outRecordService.addOutRecord(outRecord);
        return new ResponseBean<>(result);
    }

    /**
     * 更新外出记录
     * @param outRecord 更新后的外出记录对象
     * @return 更新结果的 ResponseBean
     */
    @PutMapping("/update")
    public ResponseBean<Boolean> updateOutRecord(@RequestBody OutRecord outRecord) {
        boolean result = outRecordService.updateOutRecord(outRecord);
        return new ResponseBean<>(result);
    }
    /**
     * 根据客户 ID 查询外出记录
     * @param customerId 客户的唯一标识符
     * @return 包含符合条件的外出记录列表的 ResponseBean
     */
    @GetMapping("/customer/{customerId}")
    public ResponseBean<List<OutRecord>> getOutRecordsByCustomerId(@PathVariable Integer customerId) {
        List<OutRecord> outRecords = outRecordService.getOutRecordsByCustomerId(customerId);
        return new ResponseBean<>(outRecords);
    }

    /**
     * 根据 ID 逻辑删除外出记录
     * @param id 外出记录的唯一标识符
     * @return 删除结果的 ResponseBean
     */
    @DeleteMapping("/delete/{id}")
    public ResponseBean<Boolean> deleteOutRecord(@PathVariable Integer id) {
        boolean result = outRecordService.deleteOutRecord(id);
        return new ResponseBean<>(result);
    }
}